package cn.aitrox.ry.service.auth.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.service.auth.dao.AuthUserRoleDao;
import cn.aitrox.ry.service.auth.entity.AuthResourceEntity;
import cn.aitrox.ry.service.auth.entity.AuthUserRoleEntity;
import cn.aitrox.ry.service.auth.mapper.AuthUserRoleMapper;
import cn.aitrox.ry.util.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AuthUserRoleDaoImpl extends BaseDaoImpl<AuthUserRoleEntity> implements AuthUserRoleDao {

    @Autowired
    private AuthUserRoleMapper mapper;

    @Override
    public void batchInsert(List<AuthUserRoleEntity> list) {
        if(ArrayUtil.isEmpty(list)) {
            return;
        }
        super.batchInsert(list, 1000, new MapperSqlCallback<AuthUserRoleEntity>() {
            @Override
            public void batchInsert(List<AuthUserRoleEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public void deleteByUserIdRoleIds(Integer userId, List<Integer> roleIds) {
        mapper.deleteByUserIdRoleIds(userId, roleIds);
    }

    @Override
    public void deleteByRoleIds(List<Integer> roleIds) {
        mapper.deleteByRoleIds(roleIds);
    }

    @Override
    public void deleteByUserIdsRoleIds(List<Integer> userIds, List<Integer> roleIds) {
        mapper.deleteByUserIdsRoleIds(userIds, roleIds);
    }

    @Override
    public List<AuthUserRoleEntity> findByUserIds(List<Integer> userIds) {
        return mapper.findByUserIds(userIds);
    }

    @Override
    public List<AuthResourceEntity> findResoureByUserId(Integer userId) {
        return mapper.findResoureByUserId(userId);
    }
}
